<?
/*<@
 import ("jsml/jsml.css");
 import ("jsml/jsml.js");
 import ("jsml/jquery-1.6.4.min.js");
 import ("jsml/json2.js");
 import ("jsml_Reflection");
 @>*/
import ("jsml_JObject");
import ("jsml_Config");
class Jsml{
	//<@
	public static function main(){
		$beanStr = $_REQUEST['bean'];
		$funcStr = $_REQUEST['function'];
		$paramArrayStr = $_REQUEST['paramArray'];
		if($paramArrayStr==null) {
			$paramArrayStr = file_get_contents("php://input");
		}
		//debug
		$paramArrayStr = str_replace("\\'", '"', $paramArrayStr);
		//
		
		if($beanStr == null && $funcStr == null && $paramArrayStr == null){
			if($_REQUEST['client'] != null){
				$beanStr = "jsml_parser_ParserConfig/ParserView";
				$funcStr = "parse";
				$paramArrayStr = '["'.$_REQUEST['client'].'"]';
			} else if($_REQUEST['server'] != null){
				$arr = explode("/", $_REQUEST['server'], 3);
				$beanStr = $arr[0];
				
				$arr2 = explode("_", $beanStr);
				$arr2[count($arr2)-1] = $arr2[count($arr2)-2]."Config/".$arr2[count($arr2)-1];
				$beanStr = implode("_", $arr2);
				
				$funcStr = $arr[1];
				$paramArrayStr = $arr[2];
			}
		}
		
		
		$paramArray = json_decode($paramArrayStr, TRUE);
		if($paramArray==null) $paramArray=array();

		$arr = explode("/", $beanStr);
		$configStr = $arr[0];
		$key = $arr[1];
		import($configStr);
		$configRef = new ReflectionClass($configStr);
		$config = $configRef->getStaticPropertyValue("config");
		$bean = $config->getBean($config->$key);

		$result = array();
		$result["return"] = call_user_func_array(array(&$bean, $funcStr), $paramArray);
		$result["__id__"] = $_REQUEST['__id__'];

		if(get_class($bean) == "jsml_parser_ParserView") return;
		if($_REQUEST['callback']!=null){
			echo $_REQUEST['callback'], '(';
			echo json_encode($result);
			echo ');';
		}else{
			echo json_encode($result);
		}
	}
	//@>
}